package com.example.demo.controller;

import com.example.demo.entity.Company;
import com.example.demo.service.CompanyService;
import com.example.demo.util.RestBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/companies")
public class CompanyController {

    @Autowired
    private CompanyService companyService;

    @GetMapping("/{id}")
    public RestBean<Company> getCompany(@PathVariable Integer id) {
        Company company = companyService.findCompanyById(id);
        return RestBean.success(company);
    }

    @PostMapping
    public RestBean<Company> createCompany(@RequestBody Company company) {
        Company created = companyService.createCompany(company);
        return RestBean.success(created, "创建成功");
        // 或者：return RestBean.success(created);
    }

    @DeleteMapping("/{id}")
    public RestBean<Void> deleteCompany(@PathVariable Integer id) {
        companyService.deleteCompany(id);
        return RestBean.success("删除成功");
        // 或者：return RestBean.success();
    }
}